<?php
/**
 * controller class for role 
 * @package naanal
 */
class ClsRole extends ClsNaanalController
{
	
        /**
         * request
         * @package naanal
         * @var string 
         */
	public $request=null;
        /**
         * get
         * @package naanal
         * @var string 
         */
	public $get=null;
        /**
         * post
         * @package naanal
         * @var string 
         */
	public $post=null;
        /**
         * files
         * @package naanal
         * @var string 
         */
	public $files=null;
        /**
         * pdo
         * @package naanal
         * @var string 
         */
	public $pdo=null;
        /**
         * controlpanel
         * @package naanal
         * @var string 
         */
	public $controlpanel=null;
        /**
         * mode
         * @package naanal
         * @var string 
         */
	public $mode="create";
	
	//private $redirect=null; 
	
	/**
         * construct
         * @package naanal
         * @param string $controlpanel
         */
	function __construct()
	{
            parent::__construct();
	}
	/**
         * get Redirect
         * @package naanal
         * @return string
         */
	function getRedirect()
	{
            return $this->redirect;
	}
	/**
         * activate
         * @package naanal
         */
	function activate()
	{    
            $this->mode="activate";
            $objUser=ClsWrapper::getInstance("role");
            $objUser->set_id($this->request["id"]);
            $objUser->set_active(1);
            $sql="update `role` set active=:active where `id`=:id";
            $this->pdo->setQuery($sql,$objUser);
            $this->redirect="{$this->urlModuleParam}=role&{$this->urlActionParam}=list";
	}
	/**
         * deactivate
         * @package saptial
         */
	function deactivate()
	{
            $this->mode="deactivate";
            $objUser=  ClsWrapper::getInstance("role");
            $objUser->set_id($this->request["id"]);
            $objUser->set_active(0);
            $sql="update `role` set active=:active where `id`=:id";
            $this->pdo->setQuery($sql,$objUser);
            $this->redirect="{$this->urlModuleParam}=role&{$this->urlActionParam}=list";
	}
	/**
         * insert
         * @package naanal
         */
	function insert()
	{       
            $this->mode="insert";
            $user_id=getUserObject()->get_id();
            $wobj=ClsWrapper::getInstance("role");
            $name=ClsNaanalRequest::getInstance()->getData("name");
            $wobj->set_name($name);
            $wobj->set_user_id($user_id);
            $wobj->update();
            $this->redirect="{$this->urlModuleParam}=role&{$this->urlActionParam}=list";
	}
	/**
         * update
         * @package naanal
         */
	function update()
	{
            $this->mode="update";
            $wobj=ClsWrapper::getInstance("role");
            $id=ClsNaanalRequest::getInstance()->getData("id");
            $name=ClsNaanalRequest::getInstance()->getData("name");
            $wobj->loadObject($id);
            $wobj->set_name($name);
            $wobj->update();
	    $this->redirect="{$this->urlModuleParam}=role&{$this->urlActionParam}=list";
	}
	/**
         * edit
         * @package naanal
         * @return array
         */
	function edit()
	{
            $this->mode="edit";
            $wobj=ClsWrapper::getInstance("role");
            $id=ClsNaanalRequest::getInstance()->getData("id");
            $wobj->loadObject($id);
            return array("form"=>$wobj);
	}
	/**
         * create
         * @package naanal
         * @return array
         */
	function create()
	{
            $this->mode="create";
            $wobj=ClsWrapper::getInstance("role");
            return array("form"=>$wobj);
	}
	/**
         * delete
         * @package naanal
         */
	function delete()
	{
            $this->mode="delete";
            $wobj=ClsWrapper::getInstance("role");
            $id=ClsNaanalRequest::getInstance()->getData("id");
            $wobj->set_id($id);
            $wobj->remove();
            $this->redirect="{$this->urlModuleParam}=role&{$this->urlActionParam}=list";
	}
	/**
         * show list
         * @package naanal
         * @return array
         */
	function show_list()
	{
            $this->mode="list";
            $arrWhere=array();
            return $this->showList($arrWhere);
            /*$sql="select role.* from role,user where role.user_id=user.id and user.client_id=".getUserObject()->get_client_id();
            $this->pdo->setQuery($sql);
            $arrObj=$this->pdo->getAllObject("ClsWRole");
            return array("list"=>$arrObj);		*/
	}
}
?>